package com.example.bookKeep.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bookKeep.entity.Process;
import com.example.bookKeep.mapper.ProcessMapper;
import com.example.bookKeep.request.BookListRequest;
import com.example.bookKeep.vo.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessService extends ServiceImpl<ProcessMapper, Process> implements IService<Process> {


    public List<String> listPurchaser() {
        return baseMapper.listPurchaser();
    }

    public List<Process> listByRequest(BookListRequest bookListRequest) {
        return baseMapper.listByRequest(bookListRequest);
    }

    public ProcessStatisticsVO homeStatistics() {
        String ym = DateUtil.thisYear() + "-" + (DateUtil.thisMonth() + 1);
        return baseMapper.homeStatistics(ym);
    }

    public ProcessStatisticsContainerVO monthStatistics(String ym) {
        List<StatisticsVO> purchaserMonthReceivedStatistics = baseMapper.purchaserMonthReceivedStatistics(ym);
        List<StatisticsVO> purchaserMonthSendStatistics = baseMapper.purchaserMonthSendStatistics(ym);

        ProcessStatisticsContainerVO statisticsContainerVO = new ProcessStatisticsContainerVO();
        statisticsContainerVO.setPurchaserReceived(purchaserMonthReceivedStatistics);
        statisticsContainerVO.setPurchaserSend(purchaserMonthSendStatistics);
        return statisticsContainerVO;
    }

    public ProcessStatisticsContainerVO yearStatistics(String ym) {
        List<StatisticsVO> purchaserMonthReceivedStatistics = baseMapper.purchaserYearReceivedStatistics(ym);
        List<StatisticsVO> purchaserMonthSendStatistics = baseMapper.purchaserYearSendStatistics(ym);

        ProcessStatisticsContainerVO statisticsContainerVO = new ProcessStatisticsContainerVO();
        statisticsContainerVO.setPurchaserReceived(purchaserMonthReceivedStatistics);
        statisticsContainerVO.setPurchaserSend(purchaserMonthSendStatistics);
        return statisticsContainerVO;
    }

    public List<ProcessPurchaserVO> listByPurchasers(BookListRequest bookListRequest) {
        return baseMapper.listByPurchasers(bookListRequest);
    }

    public void settlement(String purchaser) {
        baseMapper.updateSettlement(purchaser);
    }
}
